package com.mofang.activity.housesource;

import com.mofang.R;
import com.mofang.activity.BaseTitleViewActiviey;
import com.mofang.adapters.HouseSourceAdapter;
import com.mofang.utils.ListHeightUtils;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class HouseSourceActivity extends BaseTitleViewActiviey implements
		OnClickListener {

	private LinearLayout layout_newHouse;// 新房
	private LinearLayout layout_secondHandHouse;// 二手房
	private LinearLayout layout_rental;// 租凭
	private LinearLayout layout_privateOrdering;// 私人订制
	private LinearLayout layout_polyEffective;// 聚优惠
	private LinearLayout layout_area;// 区域
	private LinearLayout layout_type;// 类型
	private LinearLayout layout_price;// 价格
	private LinearLayout layout_sort;// 排序

	private TextView polyEffective_text;// 聚划算
	private ListView main_source_list;

	private HouseSourceAdapter mHouseSourceAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.house_source_layout);
		super.onCreate(savedInstanceState);
		setNavigationTitle("房魔方");
	}

	protected void initView() {

		layout_newHouse = (LinearLayout) findViewById(R.id.main_source_newHouse_ly);
		layout_newHouse.setOnClickListener(this);

		layout_secondHandHouse = (LinearLayout) findViewById(R.id.main_source_secondHandHouse_ly);
		layout_secondHandHouse.setOnClickListener(this);

		layout_rental = (LinearLayout) findViewById(R.id.main_source_rental_ly);
		layout_rental.setOnClickListener(this);

		layout_privateOrdering = (LinearLayout) findViewById(R.id.main_source_privateOrdering_ly);
		layout_privateOrdering.setOnClickListener(this);

		layout_polyEffective = (LinearLayout) findViewById(R.id.main_source_polyEffective_ly);
		layout_polyEffective.setOnClickListener(this);

		polyEffective_text = (TextView) findViewById(R.id.main_source_polyEffective_text);

		layout_area = (LinearLayout) findViewById(R.id.main_source_area_ly);
		layout_area.setOnClickListener(this);

		layout_type = (LinearLayout) findViewById(R.id.main_source_type_ly);
		layout_type.setOnClickListener(this);

		layout_price = (LinearLayout) findViewById(R.id.main_source_price_ly);
		layout_price.setOnClickListener(this);

		layout_sort = (LinearLayout) findViewById(R.id.main_source_sort_ly);
		layout_sort.setOnClickListener(this);

		mHouseSourceAdapter = new HouseSourceAdapter(getApplicationContext());
		main_source_list = (ListView) findViewById(R.id.main_source_list);
		main_source_list.setAdapter(mHouseSourceAdapter);
		ListHeightUtils.setListViewHeightBasedOnChildren(main_source_list);

		main_source_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int position,
					long arg3) {
				Intent intent = new Intent(HouseSourceActivity.this,
						HouseSourceDetailActivity.class);
				startActivity(intent);
			}
		});
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent;
		switch (v.getId()) {

		case R.id.main_source_newHouse_ly:
			intent = new Intent(getApplicationContext(), NewHouseActivity.class);
			intent.putExtra("newHouseTag", 1);
			startActivity(intent);
			break;

		case R.id.main_source_secondHandHouse_ly:
			intent = new Intent(getApplicationContext(), NewHouseActivity.class);
			intent.putExtra("secondHandHouseTag", 2);
			startActivity(intent);
			break;

		case R.id.main_source_rental_ly:
			intent = new Intent(getApplicationContext(), NewHouseActivity.class);
			intent.putExtra("rentalTag", 3);
			startActivity(intent);
			break;

		case R.id.main_source_privateOrdering_ly:
			intent = new Intent(getApplicationContext(), NewHouseActivity.class);
			intent.putExtra("privateOrderingTag", 4);
			startActivity(intent);
			break;

		case R.id.main_source_polyEffective_ly:
			intent = new Intent(getApplicationContext(),
					PolyEffectiveActivity.class);
			startActivity(intent);
			break;

		case R.id.main_source_area_ly:

			// intent = new Intent(getApplicationContext(), MainActivity.class);
			// startActivity(intent);

			break;
		case R.id.main_source_type_ly:

			// intent = new Intent(getApplicationContext(), MainActivity.class);
			// startActivity(intent);

			break;
		case R.id.main_source_price_ly:

			// intent = new Intent(getApplicationContext(), MainActivity.class);
			// startActivity(intent);

			break;
		case R.id.main_source_sort_ly:

			// intent = new Intent(getApplicationContext(), MainActivity.class);
			// startActivity(intent);

			break;

		default:
			break;
		}
	}

}
